package com.marvels.approve.process.controller;


import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;
import com.marvels.approve.process.dto.FaceSigAppointmentDTO;
import com.marvels.approve.process.dto.LoanApplyCaseDTO;
import com.marvels.approve.process.dto.SysUserDTO;
import com.marvels.approve.process.service.IFaceSigAppointmentService;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.exception.MarvelsBusinessException;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;

/**视频面签
 * @author liugh
 */
@RestController
@RequestMapping("/approve/spmq/service")
public class FaceSigAppointmentController {
	@Autowired
	private IFaceSigAppointmentService  faceSigAppointmentService;
	
	/**
	 * 面签预约流水分页查询
	 * @param faceSigAppointmentDTO
	 * @return
	 */
	@RequestMapping("faceSigPageList/{pageNo}/{pageSize}")
	@ResponseBody
	public MarvelsResultDTO getFaceSigAppointmentPage(@RequestBody(required=false) FaceSigAppointmentDTO faceSigAppointmentDTO,@PathVariable Integer pageNo,@PathVariable Integer pageSize){
		try {
			Page<FaceSigAppointmentDTO> PagefaceSig = faceSigAppointmentService.getFaceSigAppointmentPage(faceSigAppointmentDTO, pageNo, pageSize);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), PagefaceSig);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>面签预约流水分页查询失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>面签预约流水分页查询异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	
	/**
	 * 视频面签分页查询
	 * @param faceSigAppointmentDTO
	 * @return
	 */
	@RequestMapping("videofaceSigPageList/{pageNo}/{pageSize}")
	@ResponseBody
	public MarvelsResultDTO getVideoFaceSigAppointmentPage(@RequestBody(required=false) FaceSigAppointmentDTO faceSigAppointmentDTO,@PathVariable Integer pageNo,@PathVariable Integer pageSize){
		try {
			Page<FaceSigAppointmentDTO> PagefaceSig = faceSigAppointmentService.getVideoFaceSigAppointmentPage(faceSigAppointmentDTO, pageNo, pageSize);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), PagefaceSig);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>视频面签分页查询失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>视频面签分页查询异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	
	
	
	/**
	 * 查询面签状态
	 * @return
	 */
	@RequestMapping("/getfacesigstatus")
	@ResponseBody
	public MarvelsResultDTO getFaceSigStatus(){
		try {
			FaceSigAppointmentDTO datas = faceSigAppointmentService.findFaceSigStatus();
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), datas);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>查询面签状态失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>查询面签状态异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	/**
	 * 
	 * 新建面签任务
	 * @param faceSigAppointmentDTO
	 * @return
	 */
	@RequestMapping("/addFacesigTask")
	@ResponseBody
	public MarvelsResultDTO addFacesigTask(@RequestBody(required=false) FaceSigAppointmentDTO faceSigAppointmentDTO){
		try {
			int count= faceSigAppointmentService.addFacesigTask(faceSigAppointmentDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), count);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>新建面签任务失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>新建面签任务异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	
	/**
	 * 获取用户列表
	 * @return
	 */
	@RequestMapping("/getUserList")
	@ResponseBody
	public MarvelsResultDTO getUserList(){
		try {
			List<SysUserDTO> list= faceSigAppointmentService.selectFaceSignUsers();
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), list);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>获取用户列表失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>获取用户列表异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	
	/**
	 * 
	 * 获取用户权限
	 * @return
	 */
	@RequestMapping("/getUserCode")
	@ResponseBody
	public MarvelsResultDTO getUserCode(){
		try {
			SysUserDTO list= faceSigAppointmentService.getUserCode();
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), list);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>获取用户权限失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>获取用户权限异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	
	/**
	 * 
	 * 取件
	 * @param LoanApplyCaseDTO
	 * @return
	 */
	@RequestMapping("/takeFacesig")
	@ResponseBody
	public MarvelsResultDTO takeFacesig(@RequestBody(required=false) LoanApplyCaseDTO loanApplyCaseDTO){
		try {
			int count= faceSigAppointmentService.takeFacesig(loanApplyCaseDTO);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), count);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>面签流程取件失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>面签流程取件异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	
	
	/**
	 * 获取面签时间
	 * @param id
	 * @return
	 */
	@RequestMapping("/getRangeTime/{id}")
	@ResponseBody
	public MarvelsResultDTO getRangeTime(@PathVariable("id") String id){
		try {
			FaceSigAppointmentDTO  list=  faceSigAppointmentService.getRangeTime(id);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), list);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>获取面签时间失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>获取面签时间异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	
	}
	
	/**
	 * 更新面签
	 * @param faceSigAppointmentDTO
	 * @return
	 */
	@RequestMapping("/updateAppointment")
	@ResponseBody
	public MarvelsResultDTO updateAppointment(@RequestBody(required=false) FaceSigAppointmentDTO faceSigAppointmentDTO){
		try {
			int count =  faceSigAppointmentService.updateAppointment(faceSigAppointmentDTO,true);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), count);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>更新面签失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>更新面签异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	
	}
	
	/**
	 * 查询面签记录
	 * @param appointmentId
	 * @return
	 */
	@RequestMapping("/queryAppointmentDetail/{appointmentId}")
	@ResponseBody
	public MarvelsResultDTO queryAppointmentDetail(@PathVariable("appointmentId") String appointmentId){
		try {
			Map<String,Object> result=  faceSigAppointmentService.queryAppointmentDetail(Integer.parseInt(appointmentId));
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), result);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>查询流转记录失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>查询流转记录异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	
	}
	/**
	 * 查询预约取消状态
	 * @param appointmentId
	 * @return
	 */
	@RequestMapping("/queryCancelStatus/{appointmentId}")
	@ResponseBody
	public MarvelsResultDTO queryCancelStatus(@PathVariable("appointmentId") String appointmentId){
		try {
			FaceSigAppointmentDTO result=  faceSigAppointmentService.queryCancelStatus(Integer.parseInt(appointmentId));
			return MarvelsResultDTO.getResult(MarvelsErrorCode.SUCCESS.getValue(),MarvelsErrorCode.SUCCESS.getDesc(), result);
		} catch (MarvelsBusinessException e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>查询流转记录失败",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.FAIL.getValue(),MarvelsErrorCode.FAIL.getDesc(), e.getMessage());
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error(">>>>>>>>>>>>>>查询流转记录异常",e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(),MarvelsErrorCode.ERROR.getDesc(), e.getMessage());
		}
	}
	
	
}
	